<template>
    <div class="app-container">
        <el-row :gutter="10" class="mb8">
            <el-col :span="1.5">
                <el-button type="primary" icon="el-icon-plus" size="mini" @click="handleAdd">新增
                </el-button>
            </el-col>
            <el-col :span="1.5">
                <el-button type="primary" icon="el-icon-download" size="mini" @click="handleImport">导入
                </el-button>
            </el-col>
            <el-col :span="1.5">
                <el-button type="primary" icon="el-icon-folder-opened" size="mini" @click="handleShare">打开配置目录
                </el-button>
            </el-col>
            <el-col :span="2.5">
                <el-select @change="tablecfg" v-model="form.obj" placeholder="请选择">
                    <el-option v-for="(item, index) in fileOption" :key="index" :value="item"></el-option>
                </el-select>
            </el-col>
        </el-row>
        <el-table class="box_table" :data="tableData" :max-height="maxHeight" style="width: 100%">
            <!--            <el-table-column label="ID" prop="id" width="40" align="center">-->
            <!--            </el-table-column>-->
            <el-table-column width="130" prop="Name" label="功能名字" align="left" show-overflow-tooltip>
            </el-table-column>
            <el-table-column prop="Remark" label="备注" align="left" show-overflow-tooltip>
            </el-table-column>
            <el-table-column label="操作" align="center" width="180" class-name="small-padding fixed-width">
                <template slot-scope="scope">
                    <el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)">修改
                    </el-button>
                    <el-button size="mini" type="text" icon="el-icon-video-play" @click="handleText(scope.row)">测试
                    </el-button>
                    <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)">删除
                    </el-button>
                </template>
            </el-table-column>
        </el-table>
        <opt ref="opt" @getList="getList"></opt>
        <textFun ref="text"></textFun>
    </div>
</template>

<script>

import opt from './opt.vue';
import textFun from './text.vue';
import { GetfunciotnList, FuncDel, Importfun, Sharefun, Getcfg,Changecfg  } from '../../../../wailsjs/go/main/App'

export default {
    name: 'MyYongjieStreaming',
    components: { opt, textFun },

    data() {
        return {
            maxHeight: 0,
            tableData: [],
            fileOption: [],
            form: {
                obs: null
            },
        };
    },
    created() {
        this.maxHeight = (window.innerHeight - 85) + 'px'
    },
    mounted() {
        this.getList();
        this.getfileList();

    },
    methods: {
      tablecfg(e){
        Changecfg(e).then(res=>{
          this.getList();


        })
      },
        // 获取配置文件
        getfileList() {
            Getcfg().then(res => {
                this.fileOption = JSON.parse(res)
            })
        },
        handleImport() {
            Importfun().then(res => {
                this.getList();
            })
        },
        handleShare() {
            Sharefun().then(res => {
                this.getList();

            })
        },
        // 获取列表
        getList() {
            // eCallFunction('getList', (data) => {
            //     console.log(data);
            //     this.tableData = JSON.parse(data);
            // })
            GetfunciotnList().then(res => {
                this.tableData = JSON.parse(res);

            })
        },
        handleAdd() {
            this.$refs.opt.handleAdd();
        },
        handleUpdate(row) {
            this.$refs.opt.handleUpdate(row);
        },
        handleText(row) {
            console.log(this.$refs)
            this.$refs.text.handleText(row);
        },

        // 删除
        handleDelete(row) {
            let _this = this;
            this.$confirm('是否确认删除该条数据', "警告", {
                confirmButtonText: "确定",
                cancelButtonText: "取消",
                type: "warning"
            }).then(function () {
                FuncDel(row.Name).then(res => {
                    if (res == '1') {
                        _this.getList()
                    }
                })
            }).catch(function () {
            });
        },

    },
};
</script>

<style lang="less" scoped>
.mb8 {
    margin-bottom: 15px;
}
</style>